/**
 * 渲染 - 选择器
 */
import React, {useImperativeHandle, useState} from 'react'

import PickerCore from './PickerCore'

const PickerOverView = React.forwardRef(({}, ref) => {
  const [visible, setVisible] = useState(false)
  const [content, setContent] = useState(null)
  const [overClickEnable, setOverClickEnable] = useState(true)
  // console.log('PickerOverView - visible=', visible)
  // console.log('PickerOverView - content=', content)

  const onDismiss = option => {
    // console.log('PickerOverView - onDismiss - option=', option)
    switch (option) {
      case -2:
        // 点击背景遮罩
        break
      case -1:
        // 点击确认：相同结果
        break
      case 0:
        // 点击取消
        break
      default:
        // 点击确认
        break
    }
    setVisible(false)
  }

  useImperativeHandle(
    ref,
    () => ({
      show: c => {
        // console.log('PickerOverView - show c=', c)
        setVisible(true)
        setContent(c)
      },
      dismiss: option => {
        // console.log('PickerOverView - dismiss option=', option)
        onDismiss(option)
      },
      changOverClickEnable: e => {
        const en = !!e
        // console.log('PickerOverView - changOverClickEnable en=', en, ' e=', e)
        setOverClickEnable(en)
      },
    }),
    [],
  )

  return (
    <PickerCore
      visible={visible}
      overClickEnable={overClickEnable}
      superCallBack={onDismiss}>
      {content}
    </PickerCore>
  )
})
export default PickerOverView
